/**
 * Created by chenyu on 17/10/19.
 */
/**
 * Created by chenyu on 17/10/14.
 */
var Promise = require('bluebird');
var HistoryInfo = require('mongoose').model('LabelHistory');

module.exports = {
    findByDate: function (start, end, id) {
        var defer = Promise.defer();
        HistoryInfo.where({$and: [{updateDate: {$gte: Number(start), $lte: Number(end)}},{$or: [{id: id}]}]}).exec(function (err, data) {
            if (err) {
                console.log(err);
                defer.reject('find error')
            } else {
                defer.resolve(data)
            }
        });
        return defer.promise
    },
    getLastData: function (start,id) {
        var defer = Promise.defer();
        HistoryInfo.findOne({$and: [{updateDate: {$lt: Number(start)}},{$or: [{id: id}]}]}).exec(function (err, data) {
            if (err) {
                console.log(err);
                defer.reject('find error')
            } else {
                defer.resolve(data)
            }
        });
        return defer.promise
    }
};